package com.ydgk.servlet;

import com.ydgk.bean.Admin;
import com.ydgk.dao.AdminDao;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(name = "AdminServlet", urlPatterns = "/AdminServlet.action")
public class AdminServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
           String aname = request.getParameter("aname");
           String apass = request.getParameter("apass");
           String aid = request.getParameter("aid");
            AdminDao adminDao = new AdminDao();
            Admin admin = adminDao.findById(Integer.parseInt(aid));
            admin.setAname(aname);
            admin.setApass(apass);
            int i = adminDao.updateById(admin);
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=UTF-8");
        PrintWriter out = response.getWriter();
        if(i>0){
            out.print("<script>window.top.location.href='login.jsp';</script>");
        }else {
            out.print("修改失败！");
        }
    }


}
